<?php
header('Content-type:text/html;charset=utf8');
/**
 * 评价控制器
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-5-06
*/

class EvaController extends Controller{
	/**
	 * 通过用户访问控制器过滤实现页面缓存
	 */
//	function filters(){
//		return array(
//			array(
//				'system.web.widgets.COutputCache + details',
//				'duration'=>1800,
//				'varyByParam'=>array('_goods_id'),//id变化 
//				
//			),//类过滤器
//		);	
//	}
	

	function filters(){
		return array(
			'accessControl'
		);
	}
/**
	 * 具体方法访问具体条件
	 */
	
	function accessRules(){
		return array(
			array(
				'allow',
				'actions'=>array('eva','evaContent'),
				'users'=>array('@'),//登陆系统的用户
			),
			array(
				'deny',
				'users'=>array('*'),//所有用户
			),
		);
	}
	
	/**
	 * 展示评论内容
	 * @param int $goods_id
	 */
	public function actioneva($goods_id,$order_no){
		$eva_model = new Eva();
		$this->layout = "order";
		$infos = $eva_model->getEvaContentByGoodsId($goods_id,$order_no);
		$this->render('eva',array('eva'=>$infos,'goods_id'=>$goods_id,'order_no'=>$order_no));
	}
	
	/**
	 * 评论功能实现
	 */
	public function actionevaContent($goods_id,$order_no){
		

		$eva_model = new Eva();
		$infos = $eva_model->getEvaContentByGoodsId($goods_id,$order_no);
		
		if($_POST['type'] == 'eva'){
			$infos = $eva_model -> CheckEva(Yii::app()->user->id,$goods_id,$order_no);
			if(!empty($infos)){
				echo 999;
				exit;
			}
			$row = $eva_model -> addEvaContent(Yii::app()->user->id,$order_no,$goods_id,$_POST['content']);
			$row2 =$eva_model -> updOrderStatus($goods_id,$order_no);
			if($row){
				echo "<tr>";
				echo "<td>".Yii::app()->user->name."</td>";
				echo "<td>".$_POST[content]."</td>";
				echo "</tr>";
			}else{
				echo 0;
			}
			exit;
		}
	}
	
	
	
	
	
	
	

}
?>